package com.wmyg.antifake.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-05
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Table(name = "bk_product")
public class Product {

    @Id
    @Column(name = "product_id")
    private String productId;

    @Column(name = "product_name")
    private String productName;

    @Column(name = "product_specs")
    private String productSpecs;

    @Column(name = "remarks")
    private String remarks;

    @Column(name = "product_logo")
    private String productLogo;

    @Lob
    @Column(name = "product_pics")
    private String productPics;

    @EqualsAndHashCode.Exclude
    @Column(name = "is_free")
    private Integer isFree = 0;

    @EqualsAndHashCode.Exclude
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "company_id")
    private Company company;

    @EqualsAndHashCode.Exclude
    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "product_id")
//    @OrderBy(value = "create_time asc")
    private Set<ProductOrigin> productOrigins = new HashSet<>();

    @EqualsAndHashCode.Exclude
    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "product_id")
//    @OrderBy(value = "create_time asc")
    private Set<NoticePolicy> policies = new HashSet<>();

    @EqualsAndHashCode.Exclude
    @CreatedDate
    @Column(name = "create_time")
    private Date createTime;

    @EqualsAndHashCode.Exclude
    @LastModifiedDate
    @Column(name = "modify_time")
    private Date modifyTime;

    @EqualsAndHashCode.Exclude
    @Lob
    @Column(name = "others")
    private String others;

}
